package com.test.daily.leetcode.y2021.m12.day1218;

/**
 * CountBattleships
 *
 * @author Tom on 2021/12/18
 */
public class Code01_CountBattleships {
    public static void main(String[] args) {
//        char[][] board = new char[][]{
//                {'X','.','.','X'},{'.','.','.','X'},{'.','.','.','X'}
//        };
        char[][] board = new char[][]{
                {'.'}
        };
        Code01_CountBattleships cc = new Code01_CountBattleships();
        System.out.println(cc.countBattleships(board));
    }
    public int countBattleships(char[][] board) {
        int m = board.length;
        int n = board[0].length;
        int count = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (board[i][j] == 'X' &&
                        ((i > 0 && j > 0 && board[i - 1][j] == '.' && board[i][j - 1] == '.')
                        ||(i == 0 && j > 0 && board[i][j-1] == '.')
                        ||(j ==0 && i > 0 && board[i-1][j] == '.')
                        || (i== 0 && j == 0)) ){
                    count++;
                }
            }
        }
        return count;
    }
}
